<?
require_once("cms/customer/om/CustomerPeer.php");

class PHP_CMS_View_Helper_Recipients {

    public function recipients($form, $operator="NOT IN") {

        $c = new Criteria();

        $c->add(CustomerPeer::CUSTOMER_ID,
            "customer_id ". $operator .
            " (SELECT customer_id FROM newsletter_customer" .
            " WHERE received = 1" .
            " AND newsletter_id = '".mysql_real_escape_string($form->getId())."')",
            Criteria::CUSTOM);


        if($operator == "NOT IN") {
            $c->add(CustomerPeer::ACTIVE, true);
            $c->add(CustomerPeer::TYPE, $form->getTypes(), Criteria::IN);
            $c->add(CustomerPeer::COUNTRY_CODE, $form->getCountries(), Criteria::IN);
        }
        
        return CustomerPeer::doSelect($c);

    }

}
?>